package com.checking.attendance.controller;

import com.checking.attendance.pojo.Clock;
import com.checking.attendance.pojo.Course;
import com.checking.attendance.pojo.Leave;
import com.checking.attendance.pojo.User;
import com.checking.attendance.service.ClockService;
import com.checking.attendance.service.CourseService;
import com.checking.attendance.service.LeaveService;
import com.checking.attendance.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class CommunalController {
    @Autowired
    private UserService userService;
    @Autowired
    private LeaveService leaveService;
    @Autowired
    private ClockService clockService;
    @Autowired
    private CourseService courseService;

    @RequestMapping(value = "/login")
    public String login(){
        return "login";
    }

    @RequestMapping(value = "/admin")
    public String admin(HttpServletRequest request){
        try {
            HttpSession session = request.getSession(true);
            session.setAttribute("user_leve", "0");
        }catch (Exception e) {
            e.printStackTrace();
        }
        return "admin";
    }

    @RequestMapping(value = "/user")
    public String user(HttpServletRequest request){
        try {
            HttpSession session = request.getSession(true);
            session.setAttribute("user_leve", "2");
        }catch (Exception e) {
            e.printStackTrace();
        }
        return "user";
    }

    @RequestMapping(value = "/teacher")
    public String teacher(HttpServletRequest request){
        try {
            HttpSession session = request.getSession(true);
            session.setAttribute("user_leve", "1");
        }catch (Exception e) {
            e.printStackTrace();
        }
        return "teacher";
    }

    @RequestMapping(value = "/adminStrationManagement")
    public String adminStrationManagement(HttpServletRequest request){
        try {
            List<User> userBean = userService.selectAll();
            if (userBean.size() != 0){
                HttpSession session = request.getSession(true);
                session.setAttribute("alluser", userBean);
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
        return "adminStrationManagement";
    }

    @RequestMapping(value = "/addUsers")
    public String addUsers(){
        return "addUsers";
    }

    @RequestMapping(value = "/adminUpdateUsers")
    public String adminUpdateUsers(){
        return "adminUpdateUsers";
    }

    @RequestMapping(value = "/personalData")
    public String personalData(){
        return "personalData";
    }

    @RequestMapping(value = "/changePassword")
    public String changePassword(){
        return "changePassword";
    }


    @RequestMapping(value = "/askForLeaveToSee")
    public String askForLeaveToSee(){
        return "askForLeaveToSee";
    }

    @RequestMapping(value = "/attendanceRecord")
    public String attendanceRecord(){
        return "attendanceRecord";
    }

    @RequestMapping(value = "/clockInClass")
    public String clockInClass(){
        return "clockInClass";
    }

    @RequestMapping(value = "/clockInSchool")
    public String clockInSchool(){
        return "clockInSchool";
    }

    @RequestMapping(value = "/requestForAbsence")
    public String requestForAbsence(){
        return "requestForAbsence";
    }

    @RequestMapping(value = "/attendanceManagement")
    public String attendanceManagement(){
        return "attendanceManagement";
    }

    @RequestMapping(value = "/askForLeaveApproval")
    public String askForLeaveApproval(HttpServletRequest request){
        try {
            List<Leave> leaves = leaveService.selectByPrimaryAll();
            if (leaves.size() != 0){
                HttpSession session = request.getSession(true);
                session.setAttribute("allleave", leaves);
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
        return "askForLeaveApproval";
    }

    @RequestMapping(value = "/attendanceStatisticsQuery")
    public String attendanceStatisticsQuery(HttpServletRequest request){
        try {
            List<Clock> clocks = clockService.queryClockRecordAll();
            if (clocks.size() != 0){
                HttpSession session = request.getSession(true);
                session.setAttribute("allclck", clocks);
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
        return "attendanceStatisticsQuery";
    }

    @RequestMapping(value = "/teacherInformationManagement")
    public String teacherInformationManagement(HttpServletRequest request){
        try {
            List<User> userBean = userService.selectByPrimaryKeyLevel("1");
            HttpSession session = request.getSession(true);
            if (userBean.size() != 0){
                session.setAttribute("allthacher", userBean);
            }else {

            }
        }catch (Exception e) {
            e.printStackTrace();
        }
        return "teacherInformationManagement";
    }

    @RequestMapping(value = "/studentInformationManagement")
    public String studentInformationManagement(HttpServletRequest request){
        try {
            List<User> userBean = userService.selectByPrimaryKeyLevel("2");
            if (userBean.size() != 0){
                HttpSession session = request.getSession(true);
                session.setAttribute("allstuden", userBean);
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
        return "studentInformationManagement";
    }

    @RequestMapping(value = "/courseInformationManagement")
    public String courseInformationManagement(){
        return "courseInformationManagement";
    }

    @RequestMapping(value = "/adminCourseInformation")
    public String adminCourseInformation(HttpServletRequest request){
        try {
            List<Course> courses = courseService.selectByPrimaryCourseAll();
            if (courses.size() != 0){
                HttpSession session = request.getSession(true);
                session.setAttribute("allcourse", courses);
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
        return "adminCourseInformation";
    }

    @RequestMapping(value = "/teacherCourseInformationManagement")
    public String teacherCourseInformationManagement(){
        return "teacherCourseInformationManagement";
    }

    @RequestMapping(value = "/assistance")
    public String assistance(){
        return "assistance";
    }

    @RequestMapping(value = "/leaveApproval")
    public String leaveApproval(){
        return "leaveApproval";
    }

    @RequestMapping(value = "/leaveDetails")
    public String leaveDetails(){
        return "leaveDetails";
    }

    @RequestMapping(value = "/addCourse")
    public String addCourse(){
        return "addCourse";
    }

    @RequestMapping(value = "/updateCourse")
    public String updateCourse(){
        return "updateCourse";
    }

    @RequestMapping(value = "/attendanceSetting")
    public String attendanceSetting(){
        return "attendanceSetting";
    }

    @RequestMapping(value = "/updateAttendanceSetting")
    public String updateAttendanceSetting(){
        return "updateAttendanceSetting";
    }

    @RequestMapping(value = "/joinNewCourse")
    public String joinNewCourse(){
        return "joinNewCourse";
    }

    @RequestMapping(value = "/myCourse")
    public String myCourse(){
        return "myCourse";
    }

    @RequestMapping(value = "/checkRecord")
    public String checkRecord(){
        return "checkRecord";
    }

    @RequestMapping(value = "/curriculumProvision")
    public String curriculumProvision(){
        return "curriculumProvision";
    }


    @RequestMapping(value = "/curriculumContent")
    public String curriculumContent(){
        return "curriculumContent";
    }

    @RequestMapping(value = "/updateCheck")
    public String updateCheck(){
        return "updateCheck";
    }


    @RequestMapping(value = "/thstuUpdateUsers")
    public String thstuUpdateUsers(){
        return "thstuUpdateUsers";
    }


}
